'''
    对象序列化
'''
import json

class B:
    def __init__(self):
        self.b = 2


class A:
    def __init__(self):
        self.font = '1'
        self.id = 1
        self.context = '1111'
        self.obj = B()

    def keys(self):
        return ['font', 'id', 'context', 'obj']

    def __getitem__(self, item):
        return getattr(self, item)


a = A()
print(dict(a))
print(json.dumps(a, default=lambda o:o.__dict__))

b = A()
print(b.__dict__)
